/**
 * 
 */
package cn.gov.msa.exception;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.servlet.HandlerExceptionResolver;
import org.springframework.web.servlet.ModelAndView;

import cn.gov.msa.dao.PubExceptionMapper;
import cn.gov.msa.model.PubException;

/**   
* @Title: MyExceptionResolver.java 
* @Package cn.gov.msa.exception 
* @Description: TODO(用一句话描述该文件做什么) 
* @author 何宇江  
* @date 2018年12月5日 下午3:16:13 
*/
public class MyExceptionResolver implements HandlerExceptionResolver {

	@Autowired
	private PubExceptionMapper pubExceptionMapper;
	
	@Override
	public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler,
			Exception ex) {
		
		try{
			String sOut= "";
			StackTraceElement[] trace = ex.getStackTrace();
			sOut += ex.getMessage() + "\r\n";
			for (StackTraceElement s : trace) {
				sOut += "\tat " + s + "\r\n";
			}
			
			PubException pubException = new PubException();
			pubException.setMessage(sOut);
			
			pubExceptionMapper.insert(pubException);
		}
		catch(Exception e){
			e.printStackTrace();
		}
		
		
		return null;
	}

}
